<template>
  <el-container>
    <el-header>
      <div class="logo">
        <img src="../assets/img/logo.jpg" alt="">
        <span>曼巴科技管理系统</span>
      </div>
      <div class="welcome"> {{ '欢迎您：' + userInfo }}</div>
      <el-button class="logout" type="info" @click="logou">退出</el-button>
    </el-header>
    <el-container>
      <el-aside :width="isFold ? '60px':'200px'">
        <div class="menufold" @click="foldClick">
          <i :class="foldIcon"></i>
        </div>
        <!--左侧菜单-->
        <el-menu
            default-active="1"
            class="el-menu-vertical-demo"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
            unique-opened
            :collapse="isFold"
            :collapse-transition="false"
            router>
          <!--一级菜单-->
          <el-submenu :index="item.id+''" v-for="item in menuList" :key="item.id">
            <template slot="title">
              <i :class="item.icon"></i>
              <span>{{ item.menuName }}</span>
            </template>
            <!--            二级菜单-->
            <el-menu-item :index="subItem.url" v-for="subItem in item.child" :key="subItem.id">
              <template slot="title">
                <i :class="subItem.icon"></i>
                <span> {{ subItem.menuName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>

import {mapGetters} from 'vuex'

export default {
  name: 'Home',
  data() {
    return {
      menuList: [],
      isFold: false,//菜单折叠
      foldIcon: 'el-icon-s-fold',
      userInfo: ''
    }
  },
  created() {
    this.getMenuList()
    this.userInfo = window.localStorage.getItem("userInfo") || ''
  },
  computed: {
    ...mapGetters(['getLoginUser'])
  },
  methods: {
    async getMenuList() {/*菜单列表*/
      const {data: res} = await this.$axios.get("/menu/tree")
      if (res.code != '0') {
        return this.$message.error(res.msg)
      }
      this.menuList = res.data
    },
    logou() {/*退出系统*/
      /*清空sessionSrore*/
      window.sessionStorage.clear();
      //window.sessionStorage.removeItem("token")
      this.$router.push("/login")
    },
    foldClick() {
      //  折叠菜单
      this.isFold = !this.isFold
      if (this.foldIcon == 'el-icon-s-fold') {
        this.foldIcon = 'el-icon-s-unfold'
      } else {
        this.foldIcon = 'el-icon-s-fold'
      }
    }
  }
}
</script>
<style scoped>
.el-container {
  height: 100%;
}

.el-header {
  background-color: #636363;
  color: #fff;
  text-align: center;
  line-height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.logo{
  flex: 25;
}
.welcome{
  flex: 3;
}
.logout{
  flex: 1;
}

.el-header img {
  width: 60px;
  height: 60px;
  border-radius: 50%;
}

.el-header div {
  display: flex
}

.el-header span {
  margin-left: 15px;
}

.el-aside {
  background-color: #545c64;
  color: #333;
}

.el-main {
  color: #333;
}

body > .el-container {
  margin-bottom: 40px;
}

.menufold {
  height: 20px;
  color: #fff;
  text-align: center;
  padding: 8px 0px;
}
</style>